package com.bz.xtcx.manager.mapper.provider;

import com.bz.xtcx.manager.utils.WzStrUtil;
import org.springframework.util.StringUtils;

public class DataStatisticsProvider {

	public String findUserGroupByCountry(String country) {
		StringBuilder sql = null;
		if(StringUtils.isEmpty(country)) {
			sql = new StringBuilder("select user_type, count(*) count from `bus_user` group by user_type");
		}else if(country.equals("1")){
			
			sql = new StringBuilder("select JSON_EXTRACT(country,'$[0]'), count(*) count from `bus_user` group by JSON_EXTRACT(country,'$[0]')");
		}
		System.out.println(sql);
		return sql.toString();
	}

    // add by wangtao on 20190103 for 对接统计增加时间区间条件 start
    public String countAllMeetingByDatetimeProvider(String startDateTime, String endDateTime) {
        StringBuilder sql = new StringBuilder("select count(*) count from `cms_meeting` ");
        sql.append("where 1 = 1 ");
        if (WzStrUtil.isNotBlank(startDateTime)) {
            sql.append("and submit_time >= '" + startDateTime + "' ");
        }
        if (WzStrUtil.isNotBlank(endDateTime)) {
            sql.append("and submit_time <= '" + endDateTime + "' ");
        }
        return sql.toString();
    }

    public String countAllSuccessMeetingByDatetimeProvider(String startDateTime, String endDateTime) {
        StringBuilder sql = new StringBuilder("select count(*) count from `cms_meeting` ");
        sql.append("where check_status = 1 ");
        if (WzStrUtil.isNotBlank(startDateTime)) {
            sql.append("and submit_time >= '" + startDateTime + "' ");
        }
        if (WzStrUtil.isNotBlank(endDateTime)) {
            sql.append("and submit_time <= '" + endDateTime + "' ");
        }
        return sql.toString();
    }

    public String countAllMeetingByTypeAndDatetimeProvider(String startDateTime, String endDateTime) {
        StringBuilder sql = new StringBuilder("select count(*) count, type_id formType from `cms_meeting` ");
        sql.append("where 1 = 1 ");
        if (WzStrUtil.isNotBlank(startDateTime)) {
            sql.append(" and submit_time >= '" + startDateTime + "' ");
        }
        if (WzStrUtil.isNotBlank(endDateTime)) {
            sql.append(" and submit_time <= '" + endDateTime + "' ");
        }
        sql.append(" group by type_id");
        return sql.toString();
    }

    public String countAllSuccessMeetingByTypeAndDatetimeProvider(String startDateTime, String endDateTime) {
        StringBuilder sql = new StringBuilder("select count(*) count, type_id formType from `cms_meeting` ");
        sql.append(" where check_status = 1 ");
        if (WzStrUtil.isNotBlank(startDateTime)) {
            sql.append(" and submit_time >= '" + startDateTime + "' ");
        }
        if (WzStrUtil.isNotBlank(endDateTime)) {
            sql.append(" and submit_time <= '" + endDateTime + "' ");
        }
        sql.append(" group by type_id");
        return sql.toString();
    }
    // add by wangtao on 20190103 for 对接统计增加时间区间条件 end
}
